import java.util.Random;
import java.util.Scanner;

public class Lab_01 {
    public static void main(String[] args) {
        // 创建随机数生成器和扫描器
        Random random = new Random();
        Scanner scanner = new Scanner(System.in);
        
        System.out.println("===== 100以内加减法口算练习 =====");
        System.out.println("本次将生成50道100以内的加减法习题，请认真作答！\n");
        
        int correctCount = 0;
        
        // 生成50道习题
        for (int i = 1; i <= 50; i++) {
            // 生成两个随机数（100以内）
            int num1 = random.nextInt(100);
            int num2 = random.nextInt(100);
            
            // 随机选择加法或减法运算
            boolean isAddition = random.nextBoolean();
            
            // 确保减法结果不为负数（适合小学生练习）
            if (!isAddition) {
                if (num1 < num2) {
                    // 交换两个数
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
            }
            
            // 计算正确答案
            int correctAnswer = isAddition ? (num1 + num2) : (num1 - num2);
            
            // 输出题目
            System.out.print("第" + i + "题: " + num1 + (isAddition ? " + " : " - ") + num2 + " = ");
            
            // 读取用户答案
            while (!scanner.hasNextInt()) {
                System.out.println("请输入有效的数字答案！");
                scanner.next();
                System.out.print("第" + i + "题: " + num1 + (isAddition ? " + " : " - ") + num2 + " = ");
            }
            int userAnswer = scanner.nextInt();
            
            // 判断答案是否正确
            if (userAnswer == correctAnswer) {
                System.out.println("✓ 正确！");
                correctCount++;
            } else {
                System.out.println("✗ 错误！正确答案是: " + correctAnswer);
            }
            System.out.println();
        }
        
        // 输出练习结果统计
        System.out.println("===== 练习完成 =====");
        System.out.println("总题数: 50道");
        System.out.println("正确题数: " + correctCount + "道");
        System.out.println("错误题数: " + (50 - correctCount) + "道");
        System.out.printf("正确率: %.1f%%\n", (correctCount / 50.0) * 100);
        
        // 根据表现给出评价
        if (correctCount == 50) {
            System.out.println("太棒了！你是数学小天才！");
        } else if (correctCount >= 45) {
            System.out.println("非常优秀！继续保持！");
        } else if (correctCount >= 40) {
            System.out.println("表现不错，继续努力！");
        } else if (correctCount >= 30) {
            System.out.println("还可以，需要多加练习哦！");
        } else {
            System.out.println("加油！多练习就能提高！");
        }
        
        scanner.close();
    }
}